/**
 * 20071130 1414: Eric Kao read.<br>
 */
package bean.reflection.basic;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

/**
 * 測試 Property Descriptor <br>
 * 有一個 method getHelloString(), 並沒有宣告, 但在 descriptor.getName(), 也會被抓取到<br>
 * <br>
 * Copyright: Copyright (c) 2001-2007<br>
 * Company: 一零四資訊科技股份有限公司
 * 
 * @author Eric.Kao(eric.kao@104.com.tw)
 * @version 1.0
 */
public class TestPropertyDescriptor
{
	PropertyDescriptor descriptors[];

	MyBean myBean;

	public TestPropertyDescriptor()
		throws IntrospectionException
	{
		myBean = new MyBean();
		myBean.setName( "eric gau" );
		myBean.setSelected( true );

		Class classBean = myBean.getClass();

		BeanInfo beanInfo = Introspector.getBeanInfo( classBean );

		descriptors = beanInfo.getPropertyDescriptors();

		// 取得 PropertyDescriptor 的 Name
		System.out.println();
		System.out.println( "********* All PropertyDescriptor Name ***********" );
		for( int i = 0; i < descriptors.length; i++ )
		{
			PropertyDescriptor descriptor = descriptors[ i ];

			String str = "Property Name:" + descriptor.getName();
			str += "        ";
			str += "Property:" + descriptor.getPropertyType();

			System.out.println( str );
		}
	}

	public static void main( String[] args )
	{
		try
		{
			new TestPropertyDescriptor();
		}
		catch( IntrospectionException ex )
		{
			ex.printStackTrace();
		}
	}
}
